//package cn.jingyinghui.repository;
//
//// 其他导入保持不变
//import cn.jingyinghui.model.Product;
//import io.qdrant.client.QdrantClient;
//import io.qdrant.client.grpc.Points.Vectors;
//import io.qdrant.client.grpc.Points.PointStruct;
//import io.qdrant.client.grpc.Points.PointId;
//import io.qdrant.client.grpc.Points.UpsertPoints;
//import io.qdrant.client.grpc.Points.Value;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Repository;
//
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//@Repository
//public class ProductRepository {
//
//    private static final String COLLECTION_NAME = "products";
//
//    @Autowired
//    private QdrantClient client;
//
//    public void saveProduct(Product product, List<Float> embedding) {
//        try {
//            // 构造Point
//            PointStruct point = PointStruct.newBuilder()
//                    .setId(PointId.newBuilder().setNum(product.getId()).build())
//                    .setVectors(Vectors.newBuilder().addAllVector(embedding).build())
//                    .putAllPayload(convertAttributes(product.getAttributes()))
//                    .build();
//
//            // 存储到Qdrant
//            client.upsertAsync(UpsertPoints.newBuilder()
//                            .setCollectionName(COLLECTION_NAME)
//                            .addPoints(point)
//                            .build())
//                    .get(); // 等待操作完成
//
//            System.out.println("商品已成功存储到Qdrant!");
//        } catch (Exception e) {
//            throw new RuntimeException("Qdrant存储失败: " + e.getMessage(), e);
//        }
//    }
//
//    private Map<String, Value> convertAttributes(Map<String, String> attributes) {
//        return attributes.entrySet().stream()
//                .collect(Collectors.toMap(
//                        Map.Entry::getKey,
//                        e -> Value.newBuilder().setStringValue(e.getValue()).build()
//                ));
//    }
//}